"""
@author: chy
@file: sanchuang_pic.py
@time: 2023/12/4 17:09
"""
from bs4 import BeautifulSoup
import os
from download import downloadtext, downloadcontent

for i in range(1):
    path = "sc_pic"
    # 如果目录不存在，则自动创建目录
    if not os.path.isdir(path):
        os.mkdir(path)
    url = "https://www.sanchuangedu.cn/"
    text = downloadtext(url)
    # 提取需要的数据
    soup = BeautifulSoup(text, "lxml")
    all_picture = soup.select("img")
    for picture in all_picture:
        sc_pic = picture["src"]
        img_src = url + sc_pic
        print(img_src)
        filename = f"{path}/{sc_pic}"
        with open(filename, "wb") as f:
            # 访问封面图片
             f.write(downloadcontent(img_src))
